package com.ruoyi.web.controller.equ;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.equ.domain.EquBrand;
import com.ruoyi.equ.service.IEquBrandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备品牌Controller
 *
 * @author ruoyi
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/equ/brand")
public class EquBrandController extends BaseController
{
    @Autowired
    private IEquBrandService equBrandService;

    /**
     * 查询设备品牌列表
     */
    @PreAuthorize("@ss.hasPermi('equ:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ModelAttribute EquBrand equBrand)
    {
        startPage();
        List<EquBrand> list = equBrandService.selectEquBrandList(equBrand);
        return getDataTable(list);
    }

    /**
     * 导出设备品牌列表
     */
    @PreAuthorize("@ss.hasPermi('equ:brand:export')")
    @Log(title = "设备品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ModelAttribute EquBrand equBrand)
    {
        List<EquBrand> list = equBrandService.selectEquBrandList(equBrand);
        ExcelUtil<EquBrand> util = new ExcelUtil<EquBrand>(EquBrand.class);
        util.exportExcel(response, list, "设备品牌数据");
    }

    /**
     * 获取设备品牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('equ:brand:query')")
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable("brandId") Long brandId)
    {
        return success(equBrandService.selectEquBrandByBrandId(brandId));
    }

    /**
     * 新增设备品牌
     */
    @PreAuthorize("@ss.hasPermi('equ:brand:add')")
    @Log(title = "设备品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquBrand equBrand)
    {
        return toAjax(equBrandService.insertEquBrand(equBrand));
    }

    /**
     * 修改设备品牌
     */
    @PreAuthorize("@ss.hasPermi('equ:brand:edit')")
    @Log(title = "设备品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquBrand equBrand)
    {
        return toAjax(equBrandService.updateEquBrand(equBrand));
    }

    /**
     * 删除设备品牌
     */
    @PreAuthorize("@ss.hasPermi('equ:brand:remove')")
    @Log(title = "设备品牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{brandIds}")
    public AjaxResult remove(@PathVariable("brandIds") Long[] brandIds)
    {
        return toAjax(equBrandService.deleteEquBrandByBrandIds(brandIds));
    }
    /**
     * 查询所有设备品牌名称
     * @return
     */
    @PreAuthorize("@ss.hasPermi('equ:brand:list')")
    @GetMapping("/getAllBrandName")
    public AjaxResult getAllBrandName(){
        return success(equBrandService.getAllBrandName());
    }
}
